home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14126 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.4 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fast find algorithm
  5. Date: 11 Apr 1996 12:07:25 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4kjl9dINNne8@anvil.ugrad.cs.ubc.ca>
  8. References: <Dp8wE6.8DG@cix.compulink.co.uk> <PdvZxMlyZE9U088yn@ime.usp.br> <4k9ggs$4ov@news1.mnsinc.com> <4kbrg8$luu@druid.borland.com>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <4kbrg8$luu@druid.borland.com>,
  12. Pete Becker <pete@borland.com> wrote:
  13.  >In article <4k9ggs$4ov@news1.mnsinc.com>, huang@mnsinc.com says...
  14.  >>
  15.  >>Rogerio Brito (rbrito@ime.usp.br) wrote:
  16.  >>: huang@mnsinc.com (Szu-Wen Huang) wrote:
  17.  >>: >Falstaff (falstaff@xs4all.nl) wrote:
  18.  >>: >...
  19.  >>: >: Hashing is slightly slower than straight table lookup and can't be
  20.  >>: >: used when you want to delete elements from your table.
  21.  >>: >...
  22.  >>
  23.  >>: >Hashing can't be used when you want to delete elements?  Please explain.
  24.  >>
  25.  >>:         I think he is refering to elimination of the item of some
  26.  >>:         table.   In  such  case,  you  should  change  your  hash
  27.  >>:         function.  But if you don't have memory problems, you can
  28.  >>:         simply ignore the  location  after  it  is "deleted".  Or
  29.  >>:         depending on the implementation, you can simply unlink it
  30.  >>:         from your linked list (if it is the case, of course).
  31.  >>
  32.  >>Hash tables need to have null entries so the search will know that
  33.  >>the item doesn't exist.  I don't see why it is difficult to find
  34.  >>the item to be deleted and overwrite it with the null entry.  As
  35.  >>you said, it'll work on linked lists, but it will work also on array
  36.  >>implementations.
  37.  >
  38.  >    It depends on what you use to resolve conflicting hash values for different 
  39.  >elements. If you resolve conflicts by rehashing, or by moving to the next 
  40.  >available entry in the hash array, or any other mechanism that uses the array 
  41.  >itself as the storage location for the conflicting value, then you can't delete 
  42.  >items, cause once you do there's no way to get to the ones that used to 
  43.  >conflict. The first one you try will map to your now-empty location, and it'll 
  44.  >look like it wasn't found.
  45.  
  46. This is false, and an obvious way gets around it. You place a ``tombstone''
  47. marker in the deleted element rather than a vacant spot. I alrady mention this
  48. in another posting to this thread, but I will repeat it anyway for clarity.
  49.  
  50. When you find the item to be deleted, you set a flag. The next time you search
  51. for an element, you will see this flag and know that this is an empty spot, but
  52. that you must keep searching! But when you search for a good place for a _new_
  53. element, you _do_ stop at the tombstone: ``Ah, this spot is vacant! I can place
  54. the new element there!''. You keep rehashing until you either find a tombstone
  55. or you find a genuinely unused spot.
  56.  
  57. This is not perfect of course. Your hash table can get filled up with
  58. tombstones that waste your time when searching for an element. Of course, the
  59. check for a tombstone may be trivial with respect to your actual comparison
  60. function between the lookup key and the element keys, so this consideration
  61. might not be that important.
  62.  
  63. I'm sure that if you were to consult some ancient literature about hashing with
  64. open addressing, you would find an analysis of the effect of tombstones on the
  65. hash table performance and perhaps strategies to deal with them.
  66. -- 
  67.  
  68.